import java.io.IOException;
import java.util.Timer;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
//import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.m3g.Graphics3D;
import javax.microedition.midlet.*;


class GiaoDienChinh extends GameCanvas 
{
    Image logo,logo1;
    
   // Font tahoma=new Font("Tahoma");
    Font systemFont;
    Timer timer;
    Image tenxanh = null;
    Image tendo=null;  
   
    public GiaoDienChinh() {
       
       super(false);
       Graphics g=getGraphics();
        VeLoGo();
        g.drawImage(logo, 0, 0, Graphics.TOP|Graphics.LEFT);
        flushGraphics();
        
    }
    public void VeOVuong(Graphics g, int x1,int y1, int x2, int y2, int vien, int nen)
    {
        g.setColor(vien);
        g.drawRect(x1, y1, x2, y2);
        g.setColor(nen);
        g.fillRect(x1+1, y1+1, x2-1, y2-1);
                
    }
    public void VeTenXanh(Graphics g,int x, int y)
    {
        g.drawImage(tenxanh, x, y, Graphics.TOP|Graphics.LEFT);
    }
        public void VeTenDo(Graphics g,int x, int y)
    {
        g.drawImage(tendo, x, y, Graphics.TOP|Graphics.LEFT);
    }
    public void VeLoGo(){
        
        float giavang[]=new float[40];
        giavang[0]=(float) 46.250;
        giavang[1]=(float) 1;
        giavang[2]=(float) 46.500;
        giavang[3]=(float) 1;

        try{
            tenxanh=Image.createImage("/tenxanh1.png");
            tendo=Image.createImage("/tendo.png");
        }catch(IOException e){};
        
        
        logo=Image.createImage(getWidth(),getHeight());
        systemFont = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL );
        int rong=getWidth();
        int cao=getHeight();
        Graphics g=logo.getGraphics();
        g.setFont(systemFont);
       // DateField a=new DateField("dfd",DateField.DATE);
        
        g.drawRect(0, 0, getWidth()-1, getHeight()-1);
        g.drawRect(1, 1,getWidth()-3, getHeight()-3);
        g.setColor(255,209,0);
        //mau da cam nen thong tin 
        g.fillRect(0,0,getWidth(),35 );
        
        g.setColor(255,0,0);
        g.drawString("Thông tin giá vàng",rong/2 , 2, Graphics.TOP|Graphics.HCENTER);
        g.drawString("(Ngày 11/11/2011)",rong/2 , 16, Graphics.TOP|Graphics.HCENTER);
        
        g.setColor(217,149,40);//mau mua vao ban ra        
        g.fillRect(0, 35, getWidth(), 20);
        
        g.setColor(255,255,255);
        g.drawString("MUA VÀO", 110 , 37, Graphics.TOP|Graphics.LEFT);
        g.drawString("BÁN RA",180 , 37, Graphics.TOP|Graphics.LEFT);
//        g.drawSubstring(null, 0, 20, 0, 37,Graphics.TOP|Graphics.LEFT );
        
         //Nền địa danh
        g.setColor(249,249,249); 
        //g.fillRect(0,75, rong, 15  );
               
        VeOVuong(g, 0, 75, rong, 15, 0xe2c089, 0xf9f9f9);
        
        //đường kẻ dọc        
        g.setColor(226,192,137);
        g.drawLine(108, 35, 108, getHeight());
        g.drawLine(178, 35, 178, getHeight());
        //Địa danh
        g.drawString("TPHồ Chí Minh", 2, 75, Graphics.TOP|Graphics.LEFT);
        
         
       
        //Tên loại vàng        
        g.setColor(0,0,0);
        g.drawString("SJC tự do", 2, 58, Graphics.TOP|Graphics.LEFT);
        
        //hồ chí minh
        g.drawString("14K", 2, 90, Graphics.TOP|Graphics.LEFT);
        g.drawString("18K", 2, 105, Graphics.TOP|Graphics.LEFT);
        g.drawString("24K", 2, 120, Graphics.TOP|Graphics.LEFT);
        g.drawString("SJC10c", 2, 135, Graphics.TOP|Graphics.LEFT);
        g.drawString("SJC1c", 2, 150, Graphics.TOP|Graphics.LEFT);
        //Hà nội
        g.drawString("SJC", 2, 220, Graphics.TOP|Graphics.LEFT);
        //Đà năgx
        g.drawString("SJC", 2, 260, Graphics.TOP|Graphics.LEFT);
        //Nha trang
        g.drawString("SJC", 2, 300, Graphics.TOP|Graphics.LEFT);
        //Cần thơ
        g.drawString("SJC", 2, 320, Graphics.TOP|Graphics.LEFT);
        
        // Điền dữ liệu
        g.setColor(0xff0000);
        //Giá mua vào
        g.drawString(""+giavang[0], 110 , 58, Graphics.TOP|Graphics.LEFT);
        //Trạng thái
        if(giavang[1]==1)        
            VeTenXanh(g, 160, 58);
        else
            VeTenDo(g, 160, 58);
        //Giá Bán ra
        g.drawString(""+giavang[2], 180 , 58, Graphics.TOP|Graphics.LEFT);
        //Trạng thái
        if(giavang[3]==1)        
            VeTenXanh(g, 220, 58);
        else
            VeTenDo(g, 220, 58);
        
        
        flushGraphics();   
       // flushGraphics();
        
        
     
    }
    void VeLoGo1(){
        logo1=Image.createImage(getWidth(),getHeight());
        systemFont = Font.getFont(Font.FACE_SYSTEM, 0, Font.SIZE_MEDIUM);
        
        Graphics g=logo1.getGraphics();
        g.setFont(systemFont);
        g.setColor(251,203,132);
        g.drawRect(0, 0, getWidth()-1, getHeight()-1);
        g.drawRect(1, 1,getWidth()-3, getHeight()-3);
//        g.drawRect(0, 0, 239, 301);
//        g.drawRect(1, 1,237, 299);
//        Graphics g=getGraphics();
//        g.setFont(systemFont);
//        g.setColor(251,203,132);
//        g.drawRect(0, 0, getWidth(), getHeight());
//        g.drawRect(1, 1,getWidth()-1, getHeight()-1);
        //g.drawLine(10, 10, 60, 60);
        g.drawString("Tra cứu", 40, 50, Graphics.TOP|Graphics.LEFT);
        g.drawString("Bài tập", 50, 70, Graphics.TOP|Graphics.LEFT);
        flushGraphics();   
       // flushGraphics();
        
        
     
    }
//    public void start(){
//        Thread runner=new Thread(this);
//        runner.start();
//        
//
//
//    }
//
//    public void run() {
//         Graphics g=getGraphics();
//        VeLoGo1();
//        g.drawImage(logo1, 0, 0, Graphics.TOP|Graphics.LEFT);
//        flushGraphics();
//        
//    }
 
}



class MeNu  implements CommandListener{
    Form fmenu=new Form("");
    MeNu()
    {
        
    }
    void VeMeNu()
    {
        
    }

    public void commandAction(Command c, Displayable d) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}

public class FITHOUEDU extends MIDlet {

    public void startApp() {
        Display.getDisplay(this).setCurrent(new GiaoDienChinh());
       
       
        
        
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
}
